/**
 * author:Administrator
 * date:2016/1/4
 * desc:TODO
 */

'use strict';
var assert = require('assert');
var daoCU = require('../dao/couponUser.js');
var daoCV = require('../dao/couponVendor.js');
var daoTC = require('../dao/transCoupon.js');
var daoCnt = require('../dao/counter.js');
var daoOrder = require('../dao/order.js');

var biz = {};
module.exports = biz;

biz.reset = function * (qty) {
  var retObj;
  retObj = yield daoCU.empty();
  assert.equal(retObj.result.ok, 1);

  retObj = yield daoCV.empty();
  assert.equal(retObj.result.ok, 1);

  retObj = yield daoTC.empty();
  assert.equal(retObj.result.ok, 1);

  retObj = yield daoCnt.setCounter(daoCnt.TypesEnum.transactionid, 0);
  assert.equal(retObj, 0);

  retObj = yield daoCnt.setCounter(daoCnt.TypesEnum.couponUser, 100);
  assert.equal(retObj, 100);

  retObj = yield daoCnt.setCounter(daoCnt.TypesEnum.couponVendor, 1000);
  assert.equal(retObj, 1000);

  retObj = yield daoCV.add(qty, qty);// cvid, qtyTotal, qtyLeft
  assert.equal(retObj.errors, null);

  // order
  //retObj = yield daoOrder.empty();
  //assert.equal(retObj.errors, null);
  //yield daoOrder.addFreshOrder();s

  return {errcode: 0};
};



